package com.rds.web.controller.pms;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rds.common.annotation.Log;
import com.rds.common.enums.BusinessType;
import com.rds.system.domain.RdaTypeAttribute;
import com.rds.system.service.IRdaTypeAttributeService;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.common.core.page.TableDataInfo;

/**
 * 分类属性Controller
 *
 * @author rds
 * @date 2021-04-20
 */
@RestController
@RequestMapping("/pms/attribute")
public class RdaTypeAttributeController extends BaseController
{
    @Autowired
    private IRdaTypeAttributeService rdaTypeAttributeService;

    /**
     * 查询分类属性列表
     */
    @PreAuthorize("@ss.hasPermi('pms:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaTypeAttribute rdaTypeAttribute)
    {
        startPage();
        List<RdaTypeAttribute> list = rdaTypeAttributeService.selectRdaTypeAttributeList(rdaTypeAttribute);
        return getDataTable(list);
    }

    /**
     * 导出分类属性列表
     */
    @PreAuthorize("@ss.hasPermi('pms:attribute:export')")
    @Log(title = "分类属性", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaTypeAttribute rdaTypeAttribute)
    {
        List<RdaTypeAttribute> list = rdaTypeAttributeService.selectRdaTypeAttributeList(rdaTypeAttribute);
        ExcelUtil<RdaTypeAttribute> util = new ExcelUtil<RdaTypeAttribute>(RdaTypeAttribute.class);
        return util.exportExcel(list, "attribute");
    }

    /**
     * 获取分类属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:attribute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rdaTypeAttributeService.selectRdaTypeAttributeById(id));
    }

    /**
     * 新增分类属性
     */
    @PreAuthorize("@ss.hasPermi('pms:attribute:add')")
    @Log(title = "分类属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaTypeAttribute rdaTypeAttribute)
    {
        return toAjax(rdaTypeAttributeService.insertRdaTypeAttribute(rdaTypeAttribute));
    }

    /**
     * 修改分类属性
     */
    @PreAuthorize("@ss.hasPermi('pms:attribute:edit')")
    @Log(title = "分类属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaTypeAttribute rdaTypeAttribute)
    {
        return toAjax(rdaTypeAttributeService.updateRdaTypeAttribute(rdaTypeAttribute));
    }

    /**
     * 删除分类属性
     */
    @PreAuthorize("@ss.hasPermi('pms:attribute:remove')")
    @Log(title = "分类属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaTypeAttributeService.deleteRdaTypeAttributeByIds(ids));
    }
}
